﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Comm
{
    /// <summary>
    /// 生成HTML类
    /// 
    /// 作者：周峰
    /// 创建时间：2009-8-31
    /// </summary>
    public class CreatHTML
    {
        /// <summary>
        /// 生成HTML
        /// </summary>
        /// <param name="SorucePath">来源全路径</param>
        /// <param name="SavePath">保存路径</param>
        public static bool WriteHTML(string SorucePath, string SavePath)
        {
            bool b = false;
            System.Net.WebRequest webreq = System.Net.WebRequest.Create(SorucePath);
            System.Net.WebResponse webresp = webreq.GetResponse();
            System.IO.Stream respStream = null;
            System.IO.StreamReader read = null;
            System.IO.StreamWriter write = null;
            try
            {
                respStream = webresp.GetResponseStream();
                read = new System.IO.StreamReader(respStream, System.Text.Encoding.UTF8);
                write = new System.IO.StreamWriter(SavePath);
                write.Write(read.ReadToEnd());
                b = true;

            }
            catch (Exception ex)
            {
                b = false;
            }

            finally
            {
                if (read != null)
                {
                    read.Close();
                }
                if (write != null)
                {
                    write.Close();
                }
                if (respStream != null)
                {
                    respStream.Close();
                }
            }
            return b;
        }

        /// <summary>
        /// 检查文件是否存在
        /// </summary>
        /// <param name="SavePath"></param>
        /// <returns></returns>
        public static bool CheckHTML(string SavePath)
        {
            return File.Exists(SavePath);
        }

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="SavePath"></param>
        public static void DeleteHTML(string SavePath)
        {
            if (File.Exists(SavePath))
            {
                File.Delete(SavePath);
            }
        }
    }
}
